def spam():
    global eggs
    eggs = 'spam'
# 函数中进行声明与赋值对全局起作用

# 初始化全局变量
eggs = 'global'
spam()
print(eggs)